package com.vote.admin.controller;

import com.vote.common.returns.RespEntity;
import com.vote.admin.service.VoteUserRegisterService;
import com.vote.admin.vo.param.RegisterParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 用户投票系统注册页 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/user-register")
@Slf4j
@Api(value = "用户投票系统注册页", tags = "用户投票系统注册页")
public class VoteUserRegisterController {

    @Resource
    private VoteUserRegisterService voteUserRegisterService;

    @GetMapping("/createCode")
    @ApiOperation(value = "生成验证码")
    public RespEntity createCode(HttpServletResponse response, HttpSession session) {
        RespEntity respEntity = voteUserRegisterService.createCode(response, session);
        return respEntity;
    }

    @GetMapping("/check")
    @ApiOperation(value = "校验账号")
    @ApiImplicitParam(paramType = "query", dataType = "String", name = "username", value = "账号", required = true)
    public RespEntity checkUsername(@RequestParam(value = "username") String username) {
        RespEntity respEntity = voteUserRegisterService.checkUsername(username);
        return respEntity;
    }

    @PostMapping("/register")
    @ApiOperation(value = "注册")
    public RespEntity register(RegisterParam registerParam, HttpSession session) {
        RespEntity respEntity = voteUserRegisterService.register(registerParam, session);
        return respEntity;
    }

}
